package cn.wjzhang.middle.modules.word.controller;

import cn.wjzhang.core.beans.vo.Result;
import cn.wjzhang.middle.modules.word.beans.vo.MidWordVo;
import cn.wjzhang.middle.modules.word.beans.request.MidWordAddRequest;
import cn.wjzhang.middle.modules.word.beans.request.MidWordEditRequest;
import cn.wjzhang.middle.modules.word.beans.request.MidWordListRequest;
import cn.wjzhang.middle.modules.word.service.MidWordService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 一言Controller层
 *
 * @author wjzhang
 * @date 2023-06-28 20:13:24
 */
@Slf4j
@Api(tags = "一言")
@RestController
@RequestMapping("/v1/midword")
public class MidWordController {
    @Resource
    private MidWordService midWordService;

    @ApiOperation("一言-分页列表查询")
    @GetMapping("/list")
    public Result<IPage<MidWordVo>> queryPageList(MidWordListRequest param) {
        return Result.ok(midWordService.listWithPage(param));
    }

    @ApiOperation("一言-添加")
    @PostMapping("/add")
    public Result<Long> add(@Validated @RequestBody MidWordAddRequest addRequest) {
        return Result.ok(this.midWordService.addMidWord(addRequest));
    }

    @ApiOperation("一言-编辑")
    @PostMapping("/edit")
    public Result edit(@Validated @RequestBody MidWordEditRequest editRequest) {
        this.midWordService.editMidWord(editRequest);
        return Result.ok();
    }

    @ApiOperation("一言-通过id删除")
    @PostMapping("/delete")
    public Result delete(@RequestParam(name = "id") Long id) {
        this.midWordService.removeByIdLogic(id);
        return Result.ok();
    }

    @ApiOperation("一言-通过id查询")
    @GetMapping("/queryById")
    public Result<MidWordVo> queryById(@RequestParam(name = "id") Long id) {
        return Result.ok(midWordService.getDTO(id));
    }
}
